﻿using log4net;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Xml.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Xml.Linq;
using System.ServiceModel.Web;
using System.Xml;
using System.ServiceModel.Channels;

[ServiceContract]
public interface IDomainService
{
    [OperationContract]
    [WebGet(UriTemplate = "ClientAccessPolicy.xml")]
    Message ProvidePolicyFile();
}

public class DomainService : IDomainService
{
    #region IDomainService 成员

    public Message ProvidePolicyFile()
    {

        /*
            这样第二次访问会产生文件独占的异常，应该应改为使用 MemoryStream 缓存读取，或者直接使用
            XmlReader reader = XmlReader.Create(@"ClientAccessPolicy.xml");
         */

        //FileStream filestream = File.Open(@"ClientAccessPolicy.xml", FileMode.Open,FileAccess.Read);
        //XmlReader reader = XmlReader.Create(filestream);   

        //ClientAccessPolicy.xml文件要放在exe文件同级
        XmlReaderSettings setting = new XmlReaderSettings();
        setting.DtdProcessing = DtdProcessing.Parse;
        XmlReader reader = XmlReader.Create(@"ClientAccessPolicy.xml", setting);
        Message result = Message.CreateMessage(MessageVersion.None, "", reader);

        return result;
    }

    //CrossDomainServiceBehavior

    #endregion
}
